home *** CD-ROM | disk | FTP | other *** search
/ Skunkware 5 / Skunkware 5.iso / bin / ppmquantall < prev    next >
Text File  |  1995-07-02  |  1KB  |  46 lines

  1. #!/bin/csh -f
  2. #
  3. # ppmquantall - run ppmquant on a bunch of files all at once, so they share
  4. #               a common colormap
  5. #
  6. # WARNING: overwrites the source files with the results!!!
  7. #
  8. # Verbose explanation: Let's say you've got a dozen pixmaps that you want
  9. # to display on the screen all at the same time.  Your screen can only
  10. # display 256 different colors, but the pixmaps have a total of a thousand
  11. # or so different colors.  For a single pixmap you solve this problem with
  12. # ppmquant; this script solves it for multiple pixmaps.  All it does is
  13. # concatenate them together into one big pixmap, run ppmquant on that, and
  14. # then split it up into little pixmaps again.
  15.  
  16. if ( $#argv < 3 ) then
  17.     echo "usage:  ppmquantall <newcolors> <ppmfile> <ppmfile> ..."
  18.     exit 1
  19. endif
  20.  
  21. set newcolors=$argv[1]
  22. set files=( $argv[2-] )
  23.  
  24. set heights=()
  25. foreach i ( $files )
  26.     set heights=( $heights `head -2 $i | tail -1 | sed 's/.* //'` )
  27. end
  28.  
  29. set all=/tmp/pqa.all.$$
  30. rm -f $all
  31. pnmcat -tb -white $files | ppmquant -quiet $newcolors > $all
  32. if ( $status != 0 ) exit $status
  33.  
  34. set width=`head -2 $all | tail -1 | sed 's/ .*//'`
  35.  
  36. @ y = 0
  37. @ i = 1
  38. while ( $i <= $#files )
  39.     pnmcut 0 $y $width $heights[$i] $all | pnmcrop -quiet -white > $files[$i]
  40.     if ( $status != 0 ) exit $status
  41.     @ y = $y + $heights[$i]
  42.     @ i++
  43. end
  44.  
  45. rm -f $all
  46.